package com.ztom.agent.trace;


import com.alibaba.fastjson.JSONObject;
import com.ztom.agent.common.PropertyValues;
import com.ztom.agent.config.TraceConfig;
import com.ztom.agent.log.ILogger;
import com.ztom.agent.log.Logger;
import com.ztom.agent.log.LoggerFactory;
import com.ztom.agent.report.SpanModel;

import java.io.File;

/**
 * @author ZhangTao
 */
public class DapperSpanLifecycleListener implements SpanLifecycleListener {

    private ILogger logger = LoggerFactory.getLogger(TraceConfig.getInstance().getLogFilePath() + File.separator + PropertyValues.DEFAULT_LOG_FILE_NAME);

    public DapperSpanLifecycleListener() {
    }

    @Override
    public void spanStarted(Span span) {
        // Do nothing
    }

    @Override
    public void spanSampled(Span span) {
        // Do nothing
    }

    @Override
    public void spanCompleted(Span span) {
        Logger.debug("spanCompleted: " + span);
        SpanModel record = SpanModel.fromSpan(span);
//        MessageQueue.getInstance().add(record);
        logger.logAndFlush(JSONObject.toJSONString(record));
    }
}